﻿using Basic.HrGatewayModular.Interface;
using WeDonekRpc.Helper.Config;

namespace Basic.HrGatewayModular.Config
{
    internal class IpLimitConfig : IIpLimitConfig
    {
        public IpLimitConfig ( IConfigCollect config )
        {
            IConfigSection section = config.GetSection("Hr:IpLimit");
            section.AddRefreshEvent(this._Init);
        }

        private void _Init ( IConfigSection section, string name )
        {
            this.FailCode = section.GetValue<string[]>("FailCode", new string[] { "hr.login.user.not.find", "hr.emp.pwd.error" });
            this.IsLimit = section.GetValue<bool>("IsLimit", true);
            this.LockErrorNum = section.GetValue<int>("LockErrorNum", 10);
            this.StatisticWindow = section.GetValue<int>("StatisticWindow", 60);
            this.LockTime = section.GetValue<int>("LockTime", 120);
        }

        /// <summary>
        /// 是否限制
        /// </summary>
        public bool IsLimit { get; private set; }

        /// <summary>
        /// 锁定错误数
        /// </summary>
        public int LockErrorNum { get; private set; }

        /// <summary>
        /// 统计窗口
        /// </summary>
        public int StatisticWindow { get; private set; }
        /// <summary>
        /// 锁定时间
        /// </summary>
        public int LockTime { get; private set; }
        /// <summary>
        /// 登陆失败的错误码
        /// </summary>
        public string[] FailCode { get; private set; }
    }
}
